//
//  HLAccostAttachment.m
//  YueYue
//
//  Created by hulu001 on 2023/6/12.
//

#import "HLAccostAttachment.h"

@implementation HLAccostAttachment


- (nonnull NSString *)encodeAttachment {
    NSDictionary *dict = @{
                           @"msgType" : @(5),
                           @"body" : @{
                                   @"chatUpMsg" : self.chatUpMsg,
                                   @"imgUrl" : self.imgUrl
                                    }
                           };
    
    NSData *data = [NSJSONSerialization dataWithJSONObject:dict
                                                   options:0
                                                     error:nil];
    NSString *content = nil;
    if (data) {
        content = [[NSString alloc] initWithData:data
                                        encoding:NSUTF8StringEncoding];
    }
    return content;
}

- (CGSize)contentSize:(NIMMessage *)message cellWidth:(CGFloat)width
{
    NIMCustomObject *object = (NIMCustomObject *)message.messageObject;
    HLAccostAttachment *attachment = (HLAccostAttachment *)object.attachment;
    
    CGFloat textH = [attachment.chatUpMsg boundingRectWithSize:CGSizeMake(204, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]} context:nil].size.height;
    
    return CGSizeMake(204, textH + 76 + 8);
}

- (NSString *)cellContent:(NIMMessage *)message
{
    return @"HLAccostContentView";
}

- (UIEdgeInsets)contentViewInsets:(NIMMessage *)message
{
    return UIEdgeInsetsZero;
}

- (BOOL)shouldShowAvatar
{
    return NO;
}

@end
